package com.sws.push.config;

import org.springframework.ai.chat.client.ChatClient;

import org.springframework.ai.model.openai.autoconfigure.OpenAiConnectionProperties;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class AIConfig {

//    @Bean
//    public ChatClient AIChatClient(ChatClient.Builder chatClient) {
//        return chatClient
//                .build();
//    }

    @Bean
    public OpenAiApi openAiApi(OpenAiApi.Builder openAiApi, OpenAiConnectionProperties properties) {
        System.out.println("openAiApi: " + properties.getApiKey());
        return openAiApi
                .baseUrl(properties.getBaseUrl())
                .apiKey(properties.getApiKey())
                .build();
    }

    @Bean
    public OpenAiChatModel openAiChatModel(OpenAiChatModel.Builder openAiChatModel) {
        return openAiChatModel
                .build();
    }

    @Bean
    public OpenAiChatModel.Builder openAiChatModelBuilder(OpenAiApi openAiApi) {
        return OpenAiChatModel.builder()
                .openAiApi(openAiApi);
    }

    @Bean // 添加此方法以提供 OpenAiApi.Builder Bean
    public OpenAiApi.Builder openAiApiBuilder() {
        return new OpenAiApi.Builder();
    }

}
